#!/bin/sh

# /usr/local/etc/prometheus_alert_switch.sh

now_hour=$(date +"%H")
alert_start=06
alert_end=21

reloadRules() {
  echo "reload prometheus rules"
  curl -XPOST http://127.0.0.1:9190/-/reload
}


cd /app/instance/prometheus/rules || exit
if [ "${now_hour}" -ge ${alert_start} ] && [ "${now_hour}" -lt ${alert_end} ]; then
  echo "execute alert"
  [ -f business_rules.yml.bak ] &&  mv business_rules.yml.bak business_rules.yml && reloadRules || echo "file: business_rules.yml.bak not exists"
else
  echo "cancel alert"
  [ -f business_rules.yml ] &&  mv business_rules.yml business_rules.yml.bak && reloadRules || echo "file: business_rules.yml.bak not exists"
fi